home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 601 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. From: fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer)
  2. Message-ID: <4h4hmr$41o@news.rwth-aachen.de>
  3. X-Original-Date: 29 Feb 1996 15:45:31 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 01 Mar 96 13:42:23 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Return-Path: <daemon@meeker.UCAR.EDU>
  8. Newsgroups: comp.std.c++
  9. Subject: overriding functions a la Stroustrup allowed?
  10. Organization: RWTH -Aachen / Rechnerbetrieb Informatik
  11. Keywords: overriding functions, static elements of classes
  12. X-Newsreader: NN version 6.5.0 #3 (NOV)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMTb+zOEDnX0m9pzZAQGCQAF/RxL5EMJdG4D2LkXOLuWG40g+Fw1qs6B7
  15.     sBNqZWeqdTVxE3j7pVtXOF/RaR4KAnlV
  16.     =D2R7
  17.  
  18. In "Bjarne Stroustrup, The C++ programming language (german translation)"
  19. I found an example, which looks like this:
  20.  
  21. struct base {
  22.   base *next;
  23.   static base *list;
  24.  
  25.   base() {next = list; list = this};
  26.  
  27.   virtual void function() = 0;
  28.   // ...
  29. };
  30.  
  31. class derived : public base {
  32.   // ...
  33. public:
  34.   void function();
  35.   // ...
  36. };
  37.  
  38.  
  39. Two questions:
  40.  
  41. 1)  Does function() in class derived really override function() in base?
  42.     Does the declaration in derived really say that function is not pure
  43.     virtual and not virtual at all? I get a linker error-message, when I
  44.     use such a construction without defining the overriding function, but
  45.     neither a compiler error nor a warning. Is this correct?
  46.  
  47. 2)  What happens, when the very first object is created with a class
  48.     derived from base? The constructor of base assignes list to next, but
  49.     list is not yet initialized; so rubbish may be assigned to next. Is
  50.     there no need to initialize list first, e.g. base *base::list = 0; some-
  51.     where outside of base? I get a compiler error, if I don't do it.
  52.  
  53. Thanks in advance for any help,
  54.  
  55. Rainer Fischer.
  56. ---
  57. [ To submit articles: try just posting with your news-reader.
  58.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  59.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  60.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  61.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  62. ]
  63.